import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/dashboard',
  //   children: [{
  //     path: 'dashboard',
  //     name: 'Dashboard',
  //     component: () => import('@/views/dashboard/index'),
  //     meta: { title: '智能运维平台', icon: 'dashboard' }
  //   }]
  // },
  {
    path: '/data-acuisition',
    component: Layout,
    redirect: '/data-acquisition/protocol-management',
    name: 'Example',
    meta: { title: '数据采集', icon: 'el-icon-date' },
    children: [
      {
        path: 'protocol-management',
        name: '协议管理',
        component: () => import('@/views/data-acquisition/protocol-management/index'),
        meta: { title: '协议管理', icon: 'el-icon-document' }
      },
      {
        path: 'frequency-allocation',
        name: '频率配置',
        component: () => import('@/views/data-acquisition/frequency-allocation/index'),
        meta: { title: '频率配置', icon: 'el-icon-data-line' }
      },
      {
        path: 'data-filter',
        name: '数据过滤',
        component: () => import('@/views/data-acquisition/data-filter/index'),
        meta: { title: '数据过滤', icon: 'tree' }
      },
      {
        path: 'data-transmission',
        name: '数据传输',
        component: () => import('@/views/data-acquisition/data-transmission/index'),
        meta: { title: '数据传输', icon: 'tree' }
      },
      {
        path: 'equipment-model-management',
        name: '设备物模型管理',
        component: () => import('@/views/data-acquisition/equipment-model-management/index'),
        meta: { title: '设备物模型管理', icon: 'tree' }
      }
    ]
  },
  {
    path: '/data-collection',
    component: Layout,
    redirect: '/data-collection/data-collection-control',
    name: 'Example',
    meta: { title: '数据汇集', icon: 'el-icon-files' },
    children: [
      {
        path: 'data-collection-control',
        name: '数据采集控制',
        component: () => import('@/views/data-collection/data-collection-control/index'),
        meta: { title: '数据采集控制', icon: 'table' }
      },
      {
        path: 'api-interface-configuration',
        name: 'API接口配置',
        component: () => import('@/views/data-collection/api-interface-configuration/index'),
        meta: { title: 'API接口配置', icon: 'table' }
      },
      {
        path: 'file-upload',
        name: '文件上传',
        component: () => import('@/views/data-collection/file-upload/index'),
        meta: { title: '文件上传', icon: 'el-icon-upload' }
      },
      {
        path: 'data-cleaning',
        name: '数据清洗',
        component: () => import('@/views/data-collection/data-cleaning/index'),
        meta: { title: '数据清洗', icon: 'table' }
      },
      {
        path: 'data-fusion',
        name: '数据融合',
        component: () => import('@/views/data-collection/data-fusion/index'),
        meta: { title: '数据融合', icon: 'table' }
      },
    ]
  },
  {
    path: '/data-asset-management',
    component: Layout,
    redirect: '/data-asset-management/data-storage-management',
    name: 'Example',
    meta: { title: '数据资产管理', icon: 'el-icon-s-cooperation' },
    children: [
      {
        path: 'data-storage-management',
        name: '数据存储管理',
        component: () => import('@/views/data-asset-management/data-storage-management/index'),
        meta: { title: '数据存储管理', icon: 'table' }
      },
      {
        path: 'data-governance',
        name: '数据治理',
        component: () => import('@/views/data-asset-management/data-governance/index'),
        meta: { title: '数据治理', icon: 'table' }
      },
      {
        path: 'data-service-management',
        name: '数据服务管理',
        component: () => import('@/views/data-asset-management/data-service-management/index'),
        meta: { title: '数据服务管理', icon: 'table' }
      },
      {
        path: 'data-Lifecycle-management',
        name: '数据生命周期管理',
        component: () => import('@/views/data-asset-management/data-Lifecycle-management/index'),
        meta: { title: '数据生命周期管理', icon: 'table' }
      },
    ]
  },
  {
    path: '/data-analysis',
    component: Layout,
    redirect: '/data-analysis/off-line-data-analysis',
    name: '数据分析',
    meta: { title: '数据分析', icon: 'el-icon-data-analysis' },
    children: [
      {
        path: 'off-line-data-analysis',
        name: '离线数据分析',
        component: () => import('@/views/data-analysis/off-line-data-analysis/index'),
        meta: { title: '离线数据分析', icon: 'table' }
      },
      {
        path: 'real-time-data-analysis',
        name: '实时数据分析',
        component: () => import('@/views/data-analysis/real-time-data-analysis/index'),
        meta: { title: '实时数据分析', icon: 'table' }
      },
      {
        path: 'model-training',
        name: '模型训练',
        component: () => import('@/views/data-analysis/model-training/index'),
        meta: { title: '模型训练', icon: 'table' }
      },
      {
        path: 'analyze-service-components',
        name: '分析服务组件',
        component: () => import('@/views/data-analysis/analyze-service-components/index'),
        meta: { title: '分析服务组件', icon: 'table' }
      },
    ]
  },
  {
    path: '/data-modeling',
    component: Layout,
    redirect: '/data-modeling/data-state-modeling',
    name: '数据建模',
    meta: { title: '数据建模', icon: 'el-icon-s-data' },
    children: [
      {
        path: 'data-state-modeling',
        name: '数据状态建模',
        component: () => import('@/views/data-modeling/data-state-modeling/index'),
        meta: { title: '数据状态建模', icon: 'table' }
      },
      {
        path: 'fault-prediction-modeling',
        name: '故障预测建模',
        component: () => import('@/views/data-modeling/fault-prediction-modeling/index'),
        meta: { title: '故障预测建模', icon: 'table' }
      },
      {
        path: 'maintain-strategy-modeling',
        name: '维护策略建模',
        component: () => import('@/views/data-modeling/maintain-strategy-modeling/index'),
        meta: { title: '维护策略建模', icon: 'table' }
      },
      {
        path: 'model-management',
        name: '模型管理',
        component: () => import('@/views/data-modeling/model-management/index'),
        meta: { title: '模型管理', icon: 'table' }
      },
    ]
  },
  {
    path: '/equipment-fault-diagnosis',
    component: Layout,
    redirect: '/equipment-fault-diagnosis/data-feature-extraction',
    name: 'Example',
    meta: { title: '设备故障诊断', icon: 'el-icon-help' },
    children: [
      {
        path: 'data-feature-extraction',
        name: '数据特征提取',
        component: () => import('@/views/equipment-fault-diagnosis/data-feature-extraction/index'),
        meta: { title: '数据特征提取', icon: 'table' }
      },
      {
        path: 'application-of-fault-prediction-model',
        name: '故障预测模型应用',
        component: () => import('@/views/equipment-fault-diagnosis/application-of-fault-prediction-model/index'),
        meta: { title: '故障预测模型应用', icon: 'table' }
      },
      {
        path: 'fault-association-rule-library',
        name: '故障关联规则库',
        component: () => import('@/views/equipment-fault-diagnosis/fault-association-rule-library/index'),
        meta: { title: '故障关联规则库', icon: 'table' }
      },
      {
        path: 'fault-diagnosis-report-generation',
        name: '故障诊断报告生成',
        component: () => import('@/views/equipment-fault-diagnosis/fault-diagnosis-report-generation/index'),
        meta: { title: '故障诊断报告生成', icon: 'table' }
      },
    ]
  },
  {
    path: '/predictive-maintenance-of-equipment',
    component: Layout,
    redirect: '/predictive-maintenance-of-equipment/development-of-maintenance-strategy',
    name: 'Example',
    meta: { title: '设备预测性维护', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'development-of-maintenance-strategy',
        name: '维护策略开发',
        component: () => import('@/views/predictive-maintenance-of-equipment/development-of-maintenance-strategy/index'),
        meta: { title: '维护策略开发', icon: 'table' }
      },
      {
        path: 'work-order-generation-and-push',
        name: '工单生成与推送',
        component: () => import('@/views/predictive-maintenance-of-equipment/work-order-generation-and-push/index'),
        meta: { title: '工单生成与推送', icon: 'table' }
      },
      {
        path: 'collaborative-production-planning',
        name: '协同生产计划',
        component: () => import('@/views/predictive-maintenance-of-equipment/collaborative-production-planning/index'),
        meta: { title: '协同生产计划', icon: 'table' }
      },
      {
        path: 'maintenance-effect-evaluation',
        name: '维护效果评估',
        component: () => import('@/views/predictive-maintenance-of-equipment/maintenance-effect-evaluation/index'),
        meta: { title: '维护效果评估', icon: 'el-icon-s-custom' }
      },
    ]
  },
  {
    path: '/closed-loop-management',
    component: Layout,
    redirect: '/closed-loop-management/construction-of-knowledge-graph',
    name: 'Example',
    meta: { title: '运维经验闭环管理', icon: 'el-icon-set-up' },
    children: [
      {
        path: 'construction-of-knowledge-graph',
        name: '知识图谱构建',
        component: () => import('@/views/closed-loop-management/construction-of-knowledge-graph/index'),
        meta: { title: '知识图谱构建', icon: 'table' }
      },
      {
        path: 'NLP-knowledge-processing',
        name: 'NPL知识处理',
        component: () => import('@/views/closed-loop-management/NLP-knowledge-processing/index'),
        meta: { title: 'NPL知识处理', icon: 'table' }
      },
      {
        path: 'knowledge-update-and-optimization',
        name: '知识更新与优化',
        component: () => import('@/views/closed-loop-management/knowledge-update-and-optimization/index'),
        meta: { title: '知识更新与优化', icon: 'table' }
      },
      {
        path: 'knowledge-retrieval-and-application',
        name: '知识检索与应用',
        component: () => import('@/views/closed-loop-management/knowledge-retrieval-and-application/index'),
        meta: { title: '知识检索与应用', icon: 'el-icon-thumb' }
      },
    ]
  },
  {
    path: '/operations-visualization',
    component: Layout,
    redirect: '/operations-visualization/3D-visualization-of-equipment',
    name: 'Example',
    meta: { title: '运维可视化', icon: 'el-icon-data-board' },
    children: [
      {
        path: '3D-visualization-of-equipment',
        name: '设备3D可视化',
        component: () => import('@/views/operations-visualization/3D-visualization-of-equipment/index'),
        meta: { title: '设备3D可视化', icon: 'table' }
      },
      {
        path: 'statistical-analysis-of-indicators',
        name: '关键指标统计分析',
        component: () => import('@/views/operations-visualization/statistical-analysis-of-indicators/index'),
        meta: { title: '关键指标统计分析', icon: 'table' }
      },
      {
        path: 'visual-report-generation',
        name: '可视化报表生成',
        component: () => import('@/views/operations-visualization/visual-report-generation/index'),
        meta: { title: '可视化报表生成', icon: 'el-icon-news' }
      },
      {
        path: 'large-screen-cockpit',
        name: '大屏驾驶舱',
        component: () => import('@/views/operations-visualization/large-screen-cockpit/index'),
        meta: { title: '大屏驾驶舱', icon: 'table' }
      },
    ]
  },
  // {
  //   path: '/example',
  //   component: Layout,
  //   redirect: '/example/table',
  //   name: 'Example',
  //   meta: { title: 'Example', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: 'table',
  //       name: 'Table',
  //       component: () => import('@/views/table/index'),
  //       meta: { title: 'Table', icon: 'table' }
  //     },
  //     {
  //       path: 'tree',
  //       name: 'Tree',
  //       component: () => import('@/views/tree/index'),
  //       meta: { title: 'Tree', icon: 'tree' }
  //     }
  //   ]
  // },

  // {
  //   path: '/form',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'Form',
  //       component: () => import('@/views/form/index'),
  //       meta: { title: 'Form', icon: 'form' }
  //     }
  //   ]
  // },

  // {
  //   path: '/nested',
  //   component: Layout,
  //   redirect: '/nested/menu1',
  //   name: 'Nested',
  //   meta: {
  //     title: 'Nested',
  //     icon: 'nested'
  //   },
  //   children: [
  //     {
  //       path: 'menu1',
  //       component: () => import('@/views/nested/menu1/index'), // Parent router-view
  //       name: 'Menu1',
  //       meta: { title: 'Menu1' },
  //       children: [
  //         {
  //           path: 'menu1-1',
  //           component: () => import('@/views/nested/menu1/menu1-1'),
  //           name: 'Menu1-1',
  //           meta: { title: 'Menu1-1' }
  //         },
  //         {
  //           path: 'menu1-2',
  //           component: () => import('@/views/nested/menu1/menu1-2'),
  //           name: 'Menu1-2',
  //           meta: { title: 'Menu1-2' },
  //           children: [
  //             {
  //               path: 'menu1-2-1',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
  //               name: 'Menu1-2-1',
  //               meta: { title: 'Menu1-2-1' }
  //             },
  //             {
  //               path: 'menu1-2-2',
  //               component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
  //               name: 'Menu1-2-2',
  //               meta: { title: 'Menu1-2-2' }
  //             }
  //           ]
  //         },
  //         {
  //           path: 'menu1-3',
  //           component: () => import('@/views/nested/menu1/menu1-3'),
  //           name: 'Menu1-3',
  //           meta: { title: 'Menu1-3' }
  //         }
  //       ]
  //     },
  //     {
  //       path: 'menu2',
  //       component: () => import('@/views/nested/menu2/index'),
  //       name: 'Menu2',
  //       meta: { title: 'menu2' }
  //     }
  //   ]
  // },

  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
  //       meta: { title: 'External Link', icon: 'link' }
  //     }
  //   ]
  // },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
